//
//  FQGradientCircleView.m
//  GradientViewDemo
//
//  Created by issuser on 2021/12/24.
//

#import "FQGradientCircleView.h"
#import "FQGradientView.h"


@interface FQGradientCircleView ()

@property (nonatomic ,strong) FQGradientView *gradientView;
@property (nonatomic ,strong) FQGradientView *gradientView1;
@property (nonatomic ,strong) FQGradientView *gradientView2;
@property (nonatomic ,strong) FQGradientView *gradientView3;

@end



@implementation FQGradientCircleView

-(instancetype)initWithFrame:(CGRect)frame config:(FQGradientProgressConfig *)config
{
    if (self = [super initWithFrame:frame]) {
        self.config = config;
    }
    return self;
}

-(void)setConfig:(FQGradientProgressConfig *)config
{
    _config = config;
    
    NSArray * gradientViewArr = @[self.gradientView,self.gradientView1,self.gradientView2,self.gradientView3];
    NSNumber *sum = [self.config.angleValues valueForKeyPath:@"@sum.self"];
    CGFloat tempAngle = 0;
    NSInteger count = 0;
    for (NSNumber * value in self.config.angleValues) {
        FQGradientView * gradientView = gradientViewArr[count];
        CGFloat vlaueProgress = (value.floatValue / sum.floatValue) * 360.0;
        gradientView.progress = vlaueProgress;
        gradientView.startAngle = (tempAngle / 360.0) * M_PI * 2.0;
        tempAngle += vlaueProgress;
        count ++;
    }
}

-(FQGradientView *)gradientView
{
    if (!_gradientView) {
        _gradientView = [[FQGradientView alloc]initWithFrame:self.bounds withW:self.config.rWidth color:self.config.gradients[0]];
        [self addSubview:_gradientView];
    }
    return _gradientView;
}

-(FQGradientView *)gradientView1
{
    if (!_gradientView1) {
        _gradientView1 = [[FQGradientView alloc]initWithFrame:self.bounds withW:self.config.rWidth color:self.config.gradients[1]];
        [self addSubview:_gradientView1];
    }
    return _gradientView1;
}

-(FQGradientView *)gradientView2
{
    if (!_gradientView2) {
        _gradientView2 = [[FQGradientView alloc]initWithFrame:self.bounds withW:self.config.rWidth color:self.config.gradients[2]];
        [self addSubview:_gradientView2];
    }
    return _gradientView2;
}

-(FQGradientView *)gradientView3
{
    if (!_gradientView3) {
        _gradientView3 = [[FQGradientView alloc]initWithFrame:self.bounds withW:self.config.rWidth color:self.config.gradients[3]];
        [self addSubview:_gradientView3];
    }
    return _gradientView3;
}

@end
